package roadtripplanner1;

import java.io.IOException;
import java.io.PrintWriter;

import javax.jdo.PersistenceManager;
import javax.servlet.http.*;

import roadtripplanner1.Waypoints;
import roadtripplanner1.PMF;

import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;


public class setWaypointsServlet extends HttpServlet 
{

	public void doPost(HttpServletRequest req, HttpServletResponse resp)
	throws IOException 
	{

		String content = req.getParameter("thewaypoints");
		String user    = req.getParameter("theuser");
		Date date = new Date();
		
		Waypoints waypoints = new Waypoints(user, content, date);

		PersistenceManager pm = PMF.get().getPersistenceManager();
		try {
			pm.makePersistent(waypoints);
		} finally {
			pm.close();
		}
		PrintWriter out = resp.getWriter();
		DateFormat formatter = new SimpleDateFormat("d MMM yyyy HH:mm:ss:SSS");
	    out.println(formatter.format(date));
	}
}